/**
 * 专业数据缓存工具
 * 用于缓存专业列表，避免重复请求
 */
import type { MajorItem } from '../api/resource'

class MajorCache {
  // 一级专业列表缓存
  private topList: MajorItem[] | null = null
  
  // 子级专业缓存 (key: 父级ID, value: 子级列表)
  private childrenMap: Map<string, MajorItem[]> = new Map()
  
  /**
   * 获取一级专业列表缓存
   */
  getTopList(): MajorItem[] | null {
    return this.topList
  }
  
  /**
   * 设置一级专业列表缓存
   */
  setTopList(list: MajorItem[]): void {
    this.topList = list
  }
  
  /**
   * 获取子级专业缓存
   */
  getChildren(fatherId: string): MajorItem[] | null {
    return this.childrenMap.get(fatherId) || null
  }
  
  /**
   * 设置子级专业缓存
   */
  setChildren(fatherId: string, list: MajorItem[]): void {
    this.childrenMap.set(fatherId, list)
  }
  
  /**
   * 清空所有缓存
   */
  clear(): void {
    this.topList = null
    this.childrenMap.clear()
  }
}

// 导出单例
export const majorCache = new MajorCache()


